<template>
	<view class="beijingse mainpadding" v-if="pageShow">
		<!-- 1=待支付,2=待发货,3=待收货,4=待评论,5=售后订单(已弃用),6=已完成,7=已取消,8=取消审核中 -->
		<view class="bigtext fonweight" v-if="dataAll.state==1">等待买家付款</view>
		<view class="bigtext fonweight" v-if="dataAll.state==2">等待商家发货</view>
		<view class="bigtext fonweight" v-if="dataAll.state==3">等待买家收货</view>
		<view class="bigtext fonweight" v-if="dataAll.state==6">已完成</view>
		<view class="bigtext fonweight" v-if="dataAll.state==7">订单已取消</view>
		<view class="strongtext nofonweight margin_top1" v-if="dataAll.state==1">请您及时付款~</view>
		<view class="strongtext nofonweight margin_top1" v-if="dataAll.state==2">请您耐心等待商家发货~</view>
		<view class="strongtext nofonweight margin_top2" v-if="dataAll.state==3">物流配送中，请耐心等待</view>
		<view class="strongtext nofonweight margin_top2" v-if="dataAll.state==6">订单已完成，欢迎再次光临</view>
		<view class="strongtext nofonweight margin_top2" v-if="dataAll.state==7">您已取消订单，期待与您的下次亲密接触</view>
		<view class="radius mainpadding ffffff margin_top">
			<view class="flexleft">
				<view class="titletext fonweight margin_right3">{{dataAll.address.name}}</view>
				<view class="titletext fonweight"> {{dataAll.address.mobile}}</view>
			</view>
			<view class="titletext xiaohui margin_top2">{{dataAll.address.address}}</view>
		</view>
		<template v-if="dataAll.express_no">
			<view class="ffffff radius mainpadding ffffff margin_top2">
				<view class="flexbetween">
					<view class="sanshier xiaohei fonweight">{{dataAll.express_name}}</view>
					<view class="xiaohuang strongtext" @click="copy(dataAll.express_no)">点击复制</view>
				</view>
				<view class="ershiba xiaohei margin_top2">{{dataAll.express_no}}</view>
			</view>
		</template>
		<view class="ffffff radius margin_top mainpadding">
			<view class="ershiba zhonghei fonweight">订单商品</view>
			<view class="flexbetween margin_top" v-for="item in dataAll.goods" :key="item.id">
				<image class="sptp" :src="item.image_text" mode=""></image>
				<view class="" style="width: 77%;">
					<view class="ershiba xiaohei yhxk">{{item.title}}</view>
					<view class="flexbetween margin_top4">
						<view class="titletext xiaocheng">¥{{item.price}}</view>
						<view class="ershil xiaohui">x{{item.number}}</view>
					</view>
				</view>
			</view>
		</view>
		<view class="ffffff radius mainpadding margin_top">
			<view class="flexbetween">
				<view class="ershil zhonghei">商品金额</view>
				<view class="ershil xiaocheng">¥{{dataAll.total_price}}</view>
			</view>
			<view class="flexbetween margin_top" v-if="Number(dataAll.coupon_price)">
				<view class="ershil zhonghei">优惠金额</view>
				<view class="ershil xiaocheng">¥{{dataAll.coupon_price}}</view>
			</view>
			<view class="flexbetween margin_top">
				<view class="ershil zhonghei">支付金额</view>
				<view class="ershil xiaocheng">¥{{dataAll.pay_price}}</view>
			</view>
			<view class="flexbetween margin_top">
				<view class="ershil zhonghei">订单编号</view>
				<view class="ershil xiaohui">{{dataAll.order_no}}</view>
			</view>
			<view class="flexbetween margin_top">
				<view class="ershil zhonghei">下单时间</view>
				<view class="ershil xiaohui">{{dataAll.createtime_text}}</view>
			</view>
			<view class="flexbetween margin_top">
				<view class="ershil zhonghei">支付方式</view>
				<view class="ershil xiaohui">{{dataAll.ly!=2?'积分':'货款'}}支付</view>
			</view>
			<view class="flexbetween margin_top">
				<view class="ershil zhonghei">备注</view>
				<view class="ershil xiaohui">{{dataAll.remarks}}</view>
			</view>
		</view>
		<view class="gudingdb ffffff mainpadding flexright" v-if="dataAll.state==6 || dataAll.state==7  || dataAll.state==1 || dataAll.state==3 || dataAll.state==2">
			<view class="qxbtn flexcenter margin_left3" v-if="dataAll.state==1 || dataAll.state==2" @click="cancelorder(dataAll.id)">取消订单</view>
			<view class="xhbtn flexcenter margin_left3" v-if="dataAll.state==1" @click="payment(dataAll)">立即支付</view>
			<view class="xhbtn flexcenter margin_left3" v-if="dataAll.state==3" @click="shouhuo(dataAll.id)">确认收货</view>
			<view class="qxbtn flexcenter margin_left3" v-if="dataAll.state==6 || dataAll.state==7 " @click="deleteorder(dataAll.id)">删除订单</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				listid: "",
				dataAll: {},
				httpRequest,
				pageShow: false
			}
		},
		onLoad(options) {
			this.listid = options.id
			this.getDetail()
		},
		methods: {
			getDetail() {
				httpRequest.request('/api/order/getOrderInfo', 'GET', {
					id: this.listid
				}, false, false, true).then(res => {
					this.dataAll = res.data
					this.pageShow = true
				})
			},
			payment(item){
				httpRequest.request("/api/order/payment", 'POST', {
					order_id: item.id,
					pay_type: item.pay_type,
				}, false, false, true).then(res => {
					if(res.code==1){
						this.getDetail()
					}
					httpRequest.toast(res.msg)
				}).catch(err => {
					uni.hideLoading()
					httpRequest.toast(err.msg);
				})
			},
			cancelorder(id) {
				httpRequest.modal('提示', '是否确认取消当前订单', true, (resp) => {
					if (resp) {
						httpRequest.request('/api/order/cancelOrder', 'POST', {
							order_id: id,
						}).then(res => {
							httpRequest.toast(res.msg)
							this.getDetail()
						})
					}
				})
			},
			shouhuo(id){
				httpRequest.modal('提示', '是否确认收货', true, (resp) => {
					if (resp) {
						httpRequest.request('/api/order/confirmOrder', 'POST', {
							id: id,
						}).then(res => {
							httpRequest.toast(res.msg)
							this.getDetail()
						})
					}
				})
			},
			deleteorder(id){
				httpRequest.modal('提示', '是否确认删除当前订单', true, (resp) => {
					if (resp) {
						httpRequest.request('/api/order/delOrder', 'POST', {
							id: id,
						}).then(res => {
							httpRequest.toast(res.msg)
							setTimeout(()=>{
								uni.navigateBack(1)
							},1000)
						})
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.xhbtn {
		width: 170rpx;
		height: 67rpx;
		font-size: 26rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		color: #FF9341;
		border-radius: 120rpx;
		border: 2rpx solid #FF9341;
	}
	.qxbtn {
		width: 170rpx;
		height: 67rpx;
		font-size: 26rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		color: #666666;
		border-radius: 120rpx;
		border: 2rpx solid #666666;
	}
	.sptp {
		width: 124rpx;
		height: 124rpx;
		border-radius: 14rpx 14rpx 14rpx 14rpx;
	}
</style>
